#include <cctype>
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
  bool isPalindrome(string s) {
    /*
      judge number or digit
     */

    int lo = 0;
    int hi = s.size() - 1;

    while (lo < hi) {
      int loCh = static_cast<unsigned char>(s[lo]);

      if (!isalpha(loCh) && !isdigit(loCh)) {
        lo++;
        continue;
      }

      int hiCh = static_cast<unsigned char>(s[hi]);
      if (!isalpha(hiCh) && !isdigit(hiCh)) {
        hi--;
        continue;
      }

      if (toupper(s[lo]) == toupper(s[hi])) {
        // printf("lo:%d, hi:%d, loch:%c,, hich:%c\n", lo,hi, s[lo], s[hi]);
        lo++;
        hi--;
      } else {
        // printf("lo:%d, hi:%d, loch:%c,, hich:%c\n", lo,hi, s[lo], s[hi]);
        return false;
      }
    }
    return true;
  }
};

void testcase01() {
  printf("\n\n%s\n", __FUNCTION__);
  string s = "A man, a plan, a canal: Panama";
  Solution so;
  bool got = so.isPalindrome(s);
  bool expect = true;
  if (got != expect) {
    printf("failed, expect:%u, but got:%u\n", expect, got);
  }
}

void testcase02() {
  printf("\n\n%s\n", __FUNCTION__);
  string s = "0P";
  Solution so;
  bool got = so.isPalindrome(s);
  bool expect = false;
  if (got != expect) {
    printf("failed, expect:%u, but got:%u\n", expect, got);
  }
}

int main() {
  testcase01();
  testcase02();
  return 0;
}
